4d30a17605019d97b6f16c9d67790bbb00005dda
3 * @defgroup Skins Skins
6 if ( !defined( 'MEDIAWIKI' ) ) {
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
14 * See docs/skin.txt for more information.
19 protected $skinname = 'standard';
20 protected $mRelevantTitle = null;
21 protected $mRelevantUser = null;
24 * Fetch the set of available skins.
25 * @return array of strings
27 static function getSkinNames() {
28 global $wgValidSkinNames;
29 static $skinsInitialised = false;
31 if ( !$skinsInitialised ||
!count( $wgValidSkinNames ) ) {
32 # Get a list of available skins
33 # Build using the regular expression '^(.*).php$'
34 # Array keys are all lower case, array value keep the case used by filename
36 wfProfileIn( __METHOD__
. '-init' );
38 global $wgStyleDirectory;
40 $skinDir = dir( $wgStyleDirectory );
42 # while code from www.php.net
43 while ( false !== ( $file = $skinDir->read() ) ) {
44 // Skip non-PHP files, hidden files, and '.dep' includes
47 if ( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
49 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
53 $skinsInitialised = true;
54 wfProfileOut( __METHOD__
. '-init' );
56 return $wgValidSkinNames;
60 * Fetch the list of usable skins in regards to $wgSkipSkins.
61 * Useful for Special:Preferences and other places where you
62 * only want to show skins users _can_ use.
63 * @return array of strings
65 public static function getUsableSkins() {
68 $usableSkins = self
::getSkinNames();
70 foreach ( $wgSkipSkins as $skip ) {
71 unset( $usableSkins[$skip] );
78 * Normalize a skin preference value to a form that can be loaded.
79 * If a skin can't be found, it will fall back to the configured
80 * default (or the old 'Classic' skin if that's broken).
81 * @param $key String: 'monobook', 'standard', etc.
84 static function normalizeKey( $key ) {
85 global $wgDefaultSkin;
87 $skinNames = Skin
::getSkinNames();
90 // Don't return the default immediately;
91 // in a misconfiguration we need to fall back.
92 $key = $wgDefaultSkin;
95 if ( isset( $skinNames[$key] ) ) {
99 // Older versions of the software used a numeric setting
100 // in the user preferences.
107 if ( isset( $fallback[$key] ) ) {
108 $key = $fallback[$key];
111 if ( isset( $skinNames[$key] ) ) {
113 } else if ( isset( $skinNames[$wgDefaultSkin] ) ) {
114 return $wgDefaultSkin;
121 * Factory method for loading a skin of a given type
122 * @param $key String: 'monobook', 'standard', etc.
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
128 $key = Skin
::normalizeKey( $key );
130 $skinNames = Skin
::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = "Skin{$skinName}";
134 # Grab the skin class and initialise it.
135 if ( !MWInit
::classExists( $className ) ) {
137 if ( !defined( 'MW_COMPILED' ) ) {
138 // Preload base classes to work around APC/PHP5 bug
139 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
140 if ( file_exists( $deps ) ) {
141 include_once( $deps );
143 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
146 # Check if we got if not failback to default skin
147 if ( !MWInit
::classExists( $className ) ) {
148 # DO NOT die if the class isn't found. This breaks maintenance
149 # scripts and can cause a user account to be unrecoverable
150 # except by SQL manipulation if a previously valid skin name
151 # is no longer valid.
152 wfDebug( "Skin class does not exist: $className\n" );
153 $className = 'SkinVector';
154 if ( !defined( 'MW_COMPILED' ) ) {
155 require_once( "{$wgStyleDirectory}/Vector.php" );
159 $skin = new $className;
163 /** @return string path to the skin stylesheet */
164 function getStylesheet() {
165 return 'common/wikistandard.css';
168 /** @return string skin name */
169 public function getSkinName() {
170 return $this->skinname
;
173 function initPage( OutputPage
$out ) {
174 wfProfileIn( __METHOD__
);
176 $this->preloadExistence();
179 wfProfileOut( __METHOD__
);
183 * Preload the existence of three commonly-requested pages in a single query
185 function preloadExistence() {
186 $user = $this->getContext()->getUser();
189 $titles = array( $user->getUserPage(), $user->getTalkPage() );
192 if ( $this->getTitle()->getNamespace() == NS_SPECIAL
) {
194 } elseif ( $this->getTitle()->isTalkPage() ) {
195 $titles[] = $this->getTitle()->getSubjectPage();
197 $titles[] = $this->getTitle()->getTalkPage();
200 $lb = new LinkBatch( $titles );
201 $lb->setCaller( __METHOD__
);
206 * Set some local variables
208 protected function setMembers() {
209 $this->userpage
= $this->getContext()->getUser()->getUserPage()->getPrefixedText();
213 * Set the RequestContext used in this instance
215 * @param RequestContext $context
217 public function setContext( RequestContext
$context ) {
218 $this->mContext
= $context;
222 * Get the RequestContext used in this instance
224 * @return RequestContext
226 public function getContext() {
227 if ( !isset($this->mContext
) ) {
228 wfDebug( __METHOD__
. " called and \$mContext is null. Using RequestContext::getMain(); for sanity\n" );
229 $this->mContext
= RequestContext
::getMain();
231 return $this->mContext
;
238 public function getTitle() {
239 return $this->getContext()->getTitle();
246 public function getUser() {
247 return $this->getContext()->getUser();
251 * Get the current revision ID
255 public function getRevisionId() {
256 return $this->getContext()->getOutput()->getRevisionId();
260 * Whether the revision displayed is the latest revision of the page
264 public function isRevisionCurrent() {
265 $revID = $this->getRevisionId();
266 return $revID == 0 ||
$revID == $this->getTitle()->getLatestRevID();
270 * Set the "relevant" title
271 * @see self::getRelevantTitle()
272 * @param $t Title object to use
274 public function setRelevantTitle( $t ) {
275 $this->mRelevantTitle
= $t;
279 * Return the "relevant" title.
280 * A "relevant" title is not necessarily the actual title of the page.
281 * Special pages like Special:MovePage use set the page they are acting on
282 * as their "relevant" title, this allows the skin system to display things
283 * such as content tabs which belong to to that page instead of displaying
284 * a basic special page tab which has almost no meaning.
286 public function getRelevantTitle() {
287 if ( isset($this->mRelevantTitle
) ) {
288 return $this->mRelevantTitle
;
290 return $this->getTitle();
294 * Set the "relevant" user
295 * @see self::getRelevantUser()
296 * @param $u User object to use
298 public function setRelevantUser( $u ) {
299 $this->mRelevantUser
= $u;
303 * Return the "relevant" user.
304 * A "relevant" user is similar to a relevant title. Special pages like
305 * Special:Contributions mark the user which they are relevant to so that
306 * things like the toolbox can display the information they usually are only
307 * able to display on a user's userpage and talkpage.
310 public function getRelevantUser() {
311 if ( isset($this->mRelevantUser
) ) {
312 return $this->mRelevantUser
;
314 $title = $this->getRelevantTitle();
315 if( $title->getNamespace() == NS_USER ||
$title->getNamespace() == NS_USER_TALK
) {
316 $rootUser = strtok( $title->getText(), '/' );
317 if ( User
::isIP( $rootUser ) ) {
318 $this->mRelevantUser
= User
::newFromName( $rootUser, false );
320 $user = User
::newFromName( $rootUser );
321 if ( $user->isLoggedIn() ) {
322 $this->mRelevantUser
= $user;
325 return $this->mRelevantUser
;
331 * Outputs the HTML generated by other functions.
332 * @param $out Object: instance of OutputPage
334 abstract function outputPage( OutputPage
$out );
336 static function makeVariablesScript( $data ) {
338 return Html
::inlineScript(
339 ResourceLoader
::makeLoaderConditionalScript( ResourceLoader
::makeConfigSetScript( $data ) )
347 * To make it harder for someone to slip a user a fake
348 * user-JavaScript or user-CSS preview, a random token
349 * is associated with the login session. If it's not
350 * passed back with the preview request, we won't render
353 * @param $action String: 'edit', 'submit' etc.
356 public function userCanPreview( $action ) {
357 if ( $action != 'submit' ) {
360 if ( !$this->getContext()->getRequest()->wasPosted() ) {
363 if ( !$this->getTitle()->userCanEditCssSubpage() ) {
366 if ( !$this->getTitle()->userCanEditJsSubpage() ) {
370 return $this->getContext()->getUser()->matchEditToken(
371 $this->getContext()->getRequest()->getVal( 'wpEditToken' ) );
375 * Generated JavaScript action=raw&gen=js
376 * This used to load MediaWiki:Common.js and the skin-specific style
377 * before the ResourceLoader.
379 * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some
381 * @param $skinName String: If set, overrides the skin name
384 public function generateUserJs( $skinName = null ) {
389 * Generate user stylesheet for action=raw&gen=css
391 * @deprecated since 1.18 Use the ResourceLoader instead. This may be removed at some
395 public function generateUserStylesheet() {
402 function setupUserCss( OutputPage
$out ) {
403 global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
405 wfProfileIn( __METHOD__
);
407 $this->setupSkinUserCss( $out );
408 // Add any extension CSS
409 foreach ( $out->getExtStyle() as $url ) {
410 $out->addStyle( $url );
413 // Per-site custom styles
414 if ( $wgUseSiteCss ) {
415 $out->addModuleStyles( array( 'site', 'noscript' ) );
416 if( $this->getContext()->getUser()->isLoggedIn() ){
417 $out->addModuleStyles( 'user.groups' );
421 // Per-user custom styles
422 if ( $wgAllowUserCss ) {
423 if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview( $this->getContext()->getRequest()->getVal( 'action' ) ) ) {
424 // @FIXME: properly escape the cdata!
425 $out->addInlineStyle( $this->getContext()->getRequest()->getText( 'wpTextbox1' ) );
427 $out->addModuleStyles( 'user' );
431 // Per-user preference styles
432 if ( $wgAllowUserCssPrefs ) {
433 $out->addModuleStyles( 'user.options' );
436 wfProfileOut( __METHOD__
);
440 * Get the query to generate a dynamic stylesheet
444 public static function getDynamicStylesheetQuery() {
445 global $wgSquidMaxage;
449 'maxage' => $wgSquidMaxage,
450 'usemsgcache' => 'yes',
451 'ctype' => 'text/css',
452 'smaxage' => $wgSquidMaxage,
457 * Add skin specific stylesheets
458 * Calling this method with an $out of anything but the same OutputPage
459 * inside ->getContext()->getOutput() is deprecated. The $out arg is kept
460 * for compatibility purposes with skins.
461 * @param $out OutputPage
464 abstract function setupSkinUserCss( OutputPage
$out );
468 * @param $title Title
471 function getPageClasses( $title ) {
472 $numeric = 'ns-' . $title->getNamespace();
474 if ( $title->getNamespace() == NS_SPECIAL
) {
475 $type = 'ns-special';
476 // bug 23315: provide a class based on the canonical special page name without subpages
477 list( $canonicalName ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
478 if ( $canonicalName ) {
479 $type .= ' ' . Sanitizer
::escapeClass( "mw-special-$canonicalName" );
481 $type .= ' mw-invalidspecialpage';
483 } elseif ( $title->isTalkPage() ) {
486 $type = 'ns-subject';
489 $name = Sanitizer
::escapeClass( 'page-' . $title->getPrefixedText() );
491 return "$numeric $type $name";
495 * This will be called by OutputPage::headElement when it is creating the
496 * <body> tag, skins can override it if they have a need to add in any
497 * body attributes or classes of their own.
499 function addToBodyAttributes( $out, &$bodyAttrs ) {
500 // does nothing by default
511 function getCategoryLinks() {
512 global $wgUseCategoryBrowser, $wgContLang;
514 $out = $this->getContext()->output
;
516 if ( count( $out->mCategoryLinks
) == 0 ) {
521 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
523 // Use Unicode bidi embedding override characters,
524 // to make sure links don't smash each other up in ugly ways.
525 $dir = $wgContLang->getDir();
526 $embed = "<span dir='$dir'>";
529 $allCats = $out->getCategoryLinks();
531 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
533 if ( !empty( $allCats['normal'] ) ) {
534 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
536 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
537 $s .= '<div id="mw-normal-catlinks">' .
538 Linker
::link( Title
::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
539 . $colon . $t . '</div>';
543 if ( isset( $allCats['hidden'] ) ) {
544 if ( $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ) {
545 $class = 'mw-hidden-cats-user-shown';
546 } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY
) {
547 $class = 'mw-hidden-cats-ns-shown';
549 $class = 'mw-hidden-cats-hidden';
552 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
553 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
554 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
558 # optional 'dmoz-like' category browser. Will be shown under the list
559 # of categories an article belong to
560 if ( $wgUseCategoryBrowser ) {
561 $s .= '<br /><hr />';
563 # get a big array of the parents tree
564 $parenttree = $this->getTitle()->getParentCategoryTree();
565 # Skin object passed by reference cause it can not be
566 # accessed under the method subfunction drawCategoryBrowser
567 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
568 # Clean out bogus first entry and sort them
569 unset( $tempout[0] );
571 # Output one per line
572 $s .= implode( "<br />\n", $tempout );
579 * Render the array as a serie of links.
580 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
581 * @return String separated by >, terminate with "\n"
583 function drawCategoryBrowser( $tree ) {
586 foreach ( $tree as $element => $parent ) {
587 if ( empty( $parent ) ) {
588 # element start a new list
591 # grab the others elements
592 $return .= $this->drawCategoryBrowser( $parent ) . ' > ';
595 # add our current element to the list
596 $eltitle = Title
::newFromText( $element );
597 $return .= Linker
::link( $eltitle, $eltitle->getText() );
603 function getCategories() {
604 $out = $this->getContext()->output
;
606 $catlinks = $this->getCategoryLinks();
608 $classes = 'catlinks';
610 // Check what we're showing
611 $allCats = $out->getCategoryLinks();
612 $showHidden = $this->getContext()->getUser()->getBoolOption( 'showhiddencats' ) ||
613 $this->getTitle()->getNamespace() == NS_CATEGORY
;
615 if ( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
616 $classes .= ' catlinks-allhidden';
619 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
623 * This runs a hook to allow extensions placing their stuff after content
624 * and article metadata (e.g. categories).
625 * Note: This function has nothing to do with afterContent().
627 * This hook is placed here in order to allow using the same hook for all
628 * skins, both the SkinTemplate based ones and the older ones, which directly
629 * use this class to get their data.
631 * The output of this function gets processed in SkinTemplate::outputPage() for
632 * the SkinTemplate based skins, all other skins should directly echo it.
634 * Returns an empty string by default, if not changed by any hook function.
636 protected function afterContentHook() {
639 if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
640 // adding just some spaces shouldn't toggle the output
641 // of the whole <div/>, so we use trim() here
642 if ( trim( $data ) != '' ) {
643 // Doing this here instead of in the skins to
644 // ensure that the div has the same ID in all
646 $data = "<div id='mw-data-after-content'>\n" .
651 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
658 * Generate debug data HTML for displaying at the bottom of the main content
660 * @return String HTML containing debug data, if enabled (otherwise empty).
662 protected function generateDebugHTML() {
665 if ( $wgShowDebug ) {
666 $listInternals = $this->formatDebugHTML( $this->getContext()->getOutput()->mDebugtext
);
667 return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
668 $listInternals . "</ul>\n";
674 private function formatDebugHTML( $debugText ) {
675 global $wgDebugTimestamps;
677 $lines = explode( "\n", $debugText );
681 foreach ( $lines as $line ) {
683 if ( $wgDebugTimestamps ) {
685 if ( preg_match( '/^(\d+\.\d+\s{2})/', $line, $matches ) ) {
687 $line = substr( $line, strlen( $pre ) );
690 $display = ltrim( $line );
691 $ident = strlen( $line ) - strlen( $display );
692 $diff = $ident - $curIdent;
694 $display = $pre . $display;
695 if ( $display == '' ) {
696 $display = "\xc2\xa0";
699 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
702 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
704 $display = htmlspecialchars( $display );
708 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
709 } elseif ( $diff == 0 ) {
710 $ret .= "</li><li>\n";
712 $ret .= str_repeat( "<ul><li>\n", $diff );
714 $ret .= "<tt>$display</tt>\n";
719 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
725 * This gets called shortly before the </body> tag.
726 * @param $out OutputPage object
727 * @return String HTML-wrapped JS code to be put before </body>
729 function bottomScripts( $out ) {
730 // TODO and the suckage continues. This function is really just a wrapper around
731 // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
733 $bottomScriptText = $out->getBottomScripts( $this );
734 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
736 return $bottomScriptText;
739 /** @return string Retrievied from HTML text */
740 function printSource() {
741 $url = htmlspecialchars( $this->getTitle()->getFullURL() );
742 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
745 function getUndeleteLink() {
746 $action = $this->getContext()->getRequest()->getVal( 'action', 'view' );
748 if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) &&
749 ( $this->getTitle()->getArticleId() == 0 ||
$action == 'history' ) ) {
750 $n = $this->getTitle()->isDeleted();
753 if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) {
754 $msg = 'thisisdeleted';
756 $msg = 'viewdeleted';
762 SpecialPage
::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
763 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getContext()->getLang()->formatNum( $n ) ),
766 array( 'known', 'noclasses' )
775 function subPageSubtitle() {
776 $out = $this->getContext()->getOutput();
779 if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) {
783 if ( $out->isArticle() && MWNamespace
::hasSubpages( $out->getTitle()->getNamespace() ) ) {
784 $ptext = $this->getTitle()->getPrefixedText();
785 if ( preg_match( '/\//', $ptext ) ) {
786 $links = explode( '/', $ptext );
792 foreach ( $links as $link ) {
793 $growinglink .= $link;
795 $linkObj = Title
::newFromText( $growinglink );
797 if ( is_object( $linkObj ) && $linkObj->exists() ) {
798 $getlink = $this->link(
800 htmlspecialchars( $display ),
803 array( 'known', 'noclasses' )
809 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
811 $subpages .= '< ';
814 $subpages .= $getlink;
828 * Returns true if the IP should be shown in the header
830 function showIPinHeader() {
831 global $wgShowIPinHeader;
832 return $wgShowIPinHeader && session_id() != '';
835 function getSearchLink() {
836 $searchPage = SpecialPage
::getTitleFor( 'Search' );
837 return $searchPage->getLocalURL();
840 function escapeSearchLink() {
841 return htmlspecialchars( $this->getSearchLink() );
844 function getCopyright( $type = 'detect' ) {
845 global $wgRightsPage, $wgRightsUrl, $wgRightsText;
847 if ( $type == 'detect' ) {
848 $diff = $this->getContext()->getRequest()->getVal( 'diff' );
850 if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
857 if ( $type == 'history' ) {
858 $msg = 'history_copyright';
865 if ( $wgRightsPage ) {
866 $title = Title
::newFromText( $wgRightsPage );
867 $link = Linker
::linkKnown( $title, $wgRightsText );
868 } elseif ( $wgRightsUrl ) {
869 $link = Linker
::makeExternalLink( $wgRightsUrl, $wgRightsText );
870 } elseif ( $wgRightsText ) {
871 $link = $wgRightsText;
877 // Allow for site and per-namespace customization of copyright notice.
880 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
883 $out .= wfMsgForContent( $msg, $link );
885 $out .= wfMsg( $msg, $link );
891 function getCopyrightIcon() {
892 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
896 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
897 $out = $wgCopyrightIcon;
898 } elseif ( $wgRightsIcon ) {
899 $icon = htmlspecialchars( $wgRightsIcon );
901 if ( $wgRightsUrl ) {
902 $url = htmlspecialchars( $wgRightsUrl );
903 $out .= '<a href="' . $url . '">';
906 $text = htmlspecialchars( $wgRightsText );
907 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
909 if ( $wgRightsUrl ) {
918 * Gets the powered by MediaWiki icon.
921 function getPoweredBy() {
924 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
925 $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
926 wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
931 * Get the timestamp of the latest revision, formatted in user language
933 * @param $article Article object. Used if we're working with the current revision
936 protected function lastModified( $article ) {
937 if ( !$this->isRevisionCurrent() ) {
938 $timestamp = Revision
::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
940 $timestamp = $article->getTimestamp();
944 $d = $this->getContext()->getLang()->date( $timestamp, true );
945 $t = $this->getContext()->getLang()->time( $timestamp, true );
946 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
951 if ( wfGetLB()->getLaggedSlaveMode() ) {
952 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
958 function logoText( $align = '' ) {
959 if ( $align != '' ) {
960 $a = " align='{$align}'";
965 $mp = wfMsg( 'mainpage' );
966 $mptitle = Title
::newMainPage();
967 $url = ( is_object( $mptitle ) ?
$mptitle->escapeLocalURL() : '' );
969 $logourl = $this->getLogo();
970 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
976 * Renders a $wgFooterIcons icon acording to the method's arguments
977 * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
978 * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
980 function makeFooterIcon( $icon, $withImage = 'withImage' ) {
981 if ( is_string( $icon ) ) {
983 } else { // Assuming array
984 $url = isset($icon["url"]) ?
$icon["url"] : null;
985 unset( $icon["url"] );
986 if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
987 $html = Html
::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
989 $html = htmlspecialchars( $icon["alt"] );
992 $html = Html
::rawElement( 'a', array( "href" => $url ), $html );
999 * Gets the link to the wiki's main page.
1002 function mainPageLink() {
1004 Title
::newMainPage(),
1005 wfMsg( 'mainpage' ),
1008 array( 'known', 'noclasses' )
1014 public function footerLink( $desc, $page ) {
1015 // if the link description has been set to "-" in the default language,
1016 if ( wfMsgForContent( $desc ) == '-' ) {
1017 // then it is disabled, for all languages.
1020 // Otherwise, we display the link for the user, described in their
1021 // language (which may or may not be the same as the default language),
1022 // but we make the link target be the one site-wide page.
1023 $title = Title
::newFromText( wfMsgForContent( $page ) );
1025 return Linker
::linkKnown(
1027 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1033 * Gets the link to the wiki's privacy policy page.
1035 function privacyLink() {
1036 return $this->footerLink( 'privacy', 'privacypage' );
1040 * Gets the link to the wiki's about page.
1042 function aboutLink() {
1043 return $this->footerLink( 'aboutsite', 'aboutpage' );
1047 * Gets the link to the wiki's general disclaimers page.
1049 function disclaimerLink() {
1050 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1054 * Return URL options for the 'edit page' link.
1055 * This may include an 'oldid' specifier, if the current page view is such.
1060 function editUrlOptions() {
1061 $options = array( 'action' => 'edit' );
1063 if ( !$this->isRevisionCurrent() ) {
1064 $options['oldid'] = intval( $this->getRevisionId() );
1070 function showEmailUser( $id ) {
1071 $targetUser = User
::newFromId( $id );
1072 return $this->getContext()->getUser()->canSendEmail() && # the sending user must have a confirmed email address
1073 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1077 * Return a fully resolved style path url to images or styles stored in the common folder.
1078 * This method returns a url resolved using the configured skin style path
1079 * and includes the style version inside of the url.
1080 * @param $name String: The name or path of a skin resource file
1081 * @return String The fully resolved style path url including styleversion
1083 function getCommonStylePath( $name ) {
1084 global $wgStylePath, $wgStyleVersion;
1085 return "$wgStylePath/common/$name?$wgStyleVersion";
1089 * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
1090 * This method returns a url resolved using the configured skin style path
1091 * and includes the style version inside of the url.
1092 * @param $name String: The name or path of a skin resource file
1093 * @return String The fully resolved style path url including styleversion
1095 function getSkinStylePath( $name ) {
1096 global $wgStylePath, $wgStyleVersion;
1097 return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
1100 /* these are used extensively in SkinTemplate, but also some other places */
1101 static function makeMainPageUrl( $urlaction = '' ) {
1102 $title = Title
::newMainPage();
1103 self
::checkTitle( $title, '' );
1105 return $title->getLocalURL( $urlaction );
1108 static function makeSpecialUrl( $name, $urlaction = '' ) {
1109 $title = SpecialPage
::getSafeTitleFor( $name );
1110 return $title->getLocalURL( $urlaction );
1113 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1114 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1115 return $title->getLocalURL( $urlaction );
1118 static function makeI18nUrl( $name, $urlaction = '' ) {
1119 $title = Title
::newFromText( wfMsgForContent( $name ) );
1120 self
::checkTitle( $title, $name );
1121 return $title->getLocalURL( $urlaction );
1124 static function makeUrl( $name, $urlaction = '' ) {
1125 $title = Title
::newFromText( $name );
1126 self
::checkTitle( $title, $name );
1128 return $title->getLocalURL( $urlaction );
1132 * If url string starts with http, consider as external URL, else
1135 static function makeInternalOrExternalUrl( $name ) {
1136 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1139 return self
::makeUrl( $name );
1143 # this can be passed the NS number as defined in Language.php
1144 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1145 $title = Title
::makeTitleSafe( $namespace, $name );
1146 self
::checkTitle( $title, $name );
1148 return $title->getLocalURL( $urlaction );
1151 /* these return an array with the 'href' and boolean 'exists' */
1152 static function makeUrlDetails( $name, $urlaction = '' ) {
1153 $title = Title
::newFromText( $name );
1154 self
::checkTitle( $title, $name );
1157 'href' => $title->getLocalURL( $urlaction ),
1158 'exists' => $title->getArticleID() != 0,
1163 * Make URL details where the article exists (or at least it's convenient to think so)
1165 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1166 $title = Title
::newFromText( $name );
1167 self
::checkTitle( $title, $name );
1170 'href' => $title->getLocalURL( $urlaction ),
1175 # make sure we have some title to operate on
1176 static function checkTitle( &$title, $name ) {
1177 if ( !is_object( $title ) ) {
1178 $title = Title
::newFromText( $name );
1179 if ( !is_object( $title ) ) {
1180 $title = Title
::newFromText( '--error: link target missing--' );
1186 * Build an array that represents the sidebar(s), the navigation bar among them
1190 function buildSidebar() {
1191 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1192 wfProfileIn( __METHOD__
);
1194 $key = wfMemcKey( 'sidebar', $this->getContext()->getLang()->getCode() );
1196 if ( $wgEnableSidebarCache ) {
1197 $cachedsidebar = $parserMemc->get( $key );
1198 if ( $cachedsidebar ) {
1199 wfProfileOut( __METHOD__
);
1200 return $cachedsidebar;
1205 $this->addToSidebar( $bar, 'sidebar' );
1207 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
1208 if ( $wgEnableSidebarCache ) {
1209 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1212 wfProfileOut( __METHOD__
);
1216 * Add content from a sidebar system message
1217 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
1219 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
1221 * @param &$bar array
1222 * @param $message String
1224 function addToSidebar( &$bar, $message ) {
1225 $this->addToSidebarPlain( $bar, wfMsgForContentNoTrans( $message ) );
1229 * Add content from plain text
1231 * @param &$bar array
1232 * @param $text string
1234 function addToSidebarPlain( &$bar, $text ) {
1235 $lines = explode( "\n", $text );
1236 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
1240 foreach ( $lines as $line ) {
1241 if ( strpos( $line, '*' ) !== 0 ) {
1245 if ( strpos( $line, '**' ) !== 0 ) {
1246 $heading = trim( $line, '* ' );
1247 if ( !array_key_exists( $heading, $bar ) ) {
1248 $bar[$heading] = array();
1251 $line = trim( $line, '* ' );
1253 if ( strpos( $line, '|' ) !== false ) { // sanity check
1254 $line = MessageCache
::singleton()->transform( $line, false, null, $this->getTitle() );
1255 $line = array_map( 'trim', explode( '|', $line, 2 ) );
1256 $link = wfMsgForContent( $line[0] );
1258 if ( $link == '-' ) {
1262 $text = wfMsgExt( $line[1], 'parsemag' );
1264 if ( wfEmptyMsg( $line[1] ) ) {
1268 if ( wfEmptyMsg( $line[0] ) ) {
1272 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1275 $title = Title
::newFromText( $link );
1278 $title = $title->fixSpecialName();
1279 $href = $title->getLocalURL();
1281 $href = 'INVALID-TITLE';
1285 $bar[$heading][] = array(
1288 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
1291 } else if ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
1294 $line = substr( $line, 2, strlen( $line ) - 4 );
1296 $options = new ParserOptions();
1297 $options->setEditSection( false );
1298 $options->setInterfaceMessage( true );
1299 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
1306 if ( count( $wikiBar ) > 0 ) {
1307 $bar = array_merge( $bar, $wikiBar );
1314 * Should we include common/wikiprintable.css? Skins that have their own
1315 * print stylesheet should override this and return false. (This is an
1316 * ugly hack to get Monobook to play nicely with
1317 * OutputPage::headElement().)
1321 public function commonPrintStylesheet() {
1326 * Gets new talk page messages for the current user.
1327 * @return MediaWiki message or if no new talk page messages, nothing
1329 function getNewtalks() {
1330 $out = $this->getContext()->getOutput();
1332 $newtalks = $this->getContext()->getUser()->getNewMessageLinks();
1335 if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
1336 $userTitle = $this->getUser()->getUserPage();
1337 $userTalkTitle = $userTitle->getTalkPage();
1339 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
1340 $newMessagesLink = $this->link(
1342 wfMsgHtml( 'newmessageslink' ),
1344 array( 'redirect' => 'no' ),
1345 array( 'known', 'noclasses' )
1348 $newMessagesDiffLink = $this->link(
1350 wfMsgHtml( 'newmessagesdifflink' ),
1352 array( 'diff' => 'cur' ),
1353 array( 'known', 'noclasses' )
1357 'youhavenewmessages',
1359 $newMessagesDiffLink
1361 # Disable Squid cache
1362 $out->setSquidMaxage( 0 );
1364 } elseif ( count( $newtalks ) ) {
1365 // _>" " for BC <= 1.16
1366 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
1369 foreach ( $newtalks as $newtalk ) {
1370 $msgs[] = Xml
::element(
1372 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
1375 $parts = implode( $sep, $msgs );
1376 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
1377 $out->setSquidMaxage( 0 );
1384 * Get a cached notice
1386 * @param $name String: message name, or 'default' for $wgSiteNotice
1387 * @return String: HTML fragment
1389 private function getCachedNotice( $name ) {
1390 global $wgRenderHashAppend, $parserMemc;
1392 wfProfileIn( __METHOD__
);
1396 if( $name === 'default' ) {
1398 global $wgSiteNotice;
1399 $notice = $wgSiteNotice;
1400 if( empty( $notice ) ) {
1401 wfProfileOut( __METHOD__
);
1405 $msg = wfMessage( $name )->inContentLanguage();
1406 if( $msg->isDisabled() ) {
1407 wfProfileOut( __METHOD__
);
1410 $notice = $msg->plain();
1413 // Use the extra hash appender to let eg SSL variants separately cache.
1414 $key = wfMemcKey( $name . $wgRenderHashAppend );
1415 $cachedNotice = $parserMemc->get( $key );
1416 if( is_array( $cachedNotice ) ) {
1417 if( md5( $notice ) == $cachedNotice['hash'] ) {
1418 $notice = $cachedNotice['html'];
1427 $parsed = $this->getContext()->getOutput()->parse( $notice );
1428 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
1432 $notice = '<div id="localNotice">' .$notice . '</div>';
1433 wfProfileOut( __METHOD__
);
1438 * Get a notice based on page's namespace
1440 * @return String: HTML fragment
1442 function getNamespaceNotice() {
1443 wfProfileIn( __METHOD__
);
1445 $key = 'namespacenotice-' . $this->getTitle()->getNsText();
1446 $namespaceNotice = $this->getCachedNotice( $key );
1447 if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p><' ) {
1448 $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
1450 $namespaceNotice = '';
1453 wfProfileOut( __METHOD__
);
1454 return $namespaceNotice;
1458 * Get the site notice
1460 * @return String: HTML fragment
1462 function getSiteNotice() {
1463 wfProfileIn( __METHOD__
);
1466 if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) {
1467 if ( is_object( $this->getContext()->getUser() ) && $this->getContext()->getUser()->isLoggedIn() ) {
1468 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1470 $anonNotice = $this->getCachedNotice( 'anonnotice' );
1471 if ( !$anonNotice ) {
1472 $siteNotice = $this->getCachedNotice( 'sitenotice' );
1474 $siteNotice = $anonNotice;
1477 if ( !$siteNotice ) {
1478 $siteNotice = $this->getCachedNotice( 'default' );
1482 wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) );
1483 wfProfileOut( __METHOD__
);
1488 * Create a section edit link. This supersedes editSectionLink() and
1489 * editSectionLinkForOther().
1491 * @param $nt Title The title being linked to (may not be the same as
1492 * $wgTitle, if the section is included from a template)
1493 * @param $section string The designation of the section being pointed to,
1494 * to be included in the link, like "§ion=$section"
1495 * @param $tooltip string The tooltip to use for the link: will be escaped
1496 * and wrapped in the 'editsectionhint' message
1497 * @param $lang string Language code
1498 * @return string HTML to use for edit link
1500 public function doEditSectionLink( Title
$nt, $section, $tooltip = null, $lang = false ) {
1501 // HTML generated here should probably have userlangattributes
1502 // added to it for LTR text on RTL pages
1504 if ( !is_null( $tooltip ) ) {
1505 # Bug 25462: undo double-escaping.
1506 $tooltip = Sanitizer
::decodeCharReferences( $tooltip );
1507 $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
1509 $link = Linker
::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
1511 array( 'action' => 'edit', 'section' => $section ),
1512 array( 'noclasses', 'known' )
1515 # Run the old hook. This takes up half of the function . . . hopefully
1516 # we can rid of it someday.
1519 $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
1520 $attribs = " title=\"$attribs\"";
1523 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
1524 if ( !is_null( $result ) ) {
1525 # For reverse compatibility, add the brackets *after* the hook is
1526 # run, and even add them to hook-provided text. (This is the main
1527 # reason that the EditSectionLink hook is deprecated in favor of
1528 # DoEditSectionLink: it can't change the brackets or the span.)
1529 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $result );
1530 return "<span class=\"editsection\">$result</span>";
1533 # Add the brackets and the span, and *then* run the nice new hook, with
1534 # clean and non-redundant arguments.
1535 $result = wfMsgExt( 'editsection-brackets', array( 'escape', 'replaceafter', 'language' => $lang ), $link );
1536 $result = "<span class=\"editsection\">$result</span>";
1538 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
1543 * Use PHP's magic __call handler to intercept legacy calls to the linker
1544 * for backwards compatibility.
1546 * @param $fname String Name of called method
1547 * @param $args Array Arguments to the method
1549 function __call( $fname, $args ) {
1550 $realFunction = array( 'Linker', $fname );
1551 if ( is_callable( $realFunction ) ) {
1552 return call_user_func_array( $realFunction, $args );
1554 $className = get_class( $this );
1555 throw new MWException( "Call to undefined method $className::$fname" );